<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
  <meta name="renderer" content="webkit">

  
  <title>Android 14 平板Taskbar加载流程解析 | 龙之叶的博客</title>

  <link rel="shortcut icon" href="/images/favicon.png">
  <link rel="alternate" href="/atom.xml" title="龙之叶的博客" type="application/atom+xml">
  <meta name="description" content="Android 14 平板Taskbar加载流程解析">
<meta property="og:type" content="article">
<meta property="og:title" content="Android 14 平板Taskbar加载流程解析">
<meta property="og:url" content="http://longzhiye.top/2024/02/12/2024-02-12/index.html">
<meta property="og:site_name" content="龙之叶的博客">
<meta property="og:description" content="Android 14 平板Taskbar加载流程解析">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2024-02-11T16:00:00.000Z">
<meta property="article:modified_time" content="2024-08-29T02:40:34.922Z">
<meta property="article:author" content="龙之叶">
<meta property="article:tag" content="Android">
<meta property="article:tag" content="SystemUI">
<meta property="article:tag" content="framework">
<meta property="article:tag" content="Launcher">
<meta name="twitter:card" content="summary">

  <meta name="keywords" content=",Android,SystemUI,framework,Launcher">
  <meta name="format-detection" content="telephone=no,email=no">
  <meta name="theme-color" content="#9C27B0">

  <meta name="mobile-web-app-capable" content="yes">
  <meta name="application-name" content="龙之叶的博客">
  <meta name="msapplication-starturl" content="http://longzhiye.top/2024/02/12/2024-02-12/">
  <meta name="msapplication-navbutton-color" content="#9C27B0">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-title" content="龙之叶的博客">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <link rel="apple-touch-icon" href="/images/favicon.png">

  
    <link rel="canonical" href="http://longzhiye.top/2024/02/12/2024-02-12/">
  

  
  

  
  
  

  
<link rel="stylesheet" href="/css/mdui.css">
<link rel="stylesheet" href="/css/style.css">

  
<link rel="stylesheet" href="/custom.css">

<meta name="generator" content="Hexo 5.4.2"></head>

<body class="mdui-appbar-with-toolbar mdui-theme-primary-indigo mdui-theme-accent-pink">
  <script>var a=localStorage.getItem("mdui-theme-layout-dark");if(a){document.getElementsByTagName("body")[0].className+=" mdui-theme-layout-dark"};</script>
  <script>if(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches){document.getElementsByTagName("body")[0].className+=" mdui-theme-layout-dark"};</script>
  <script>var a=localStorage.getItem("mdui-drawer-close");if(!a){document.getElementsByTagName("body")[0].className+=" mdui-drawer-body-left"};</script>
  <header id="header" class="mdui-appbar mdui-appbar-fixed mdui-appbar-scroll-hide mdui-appbar-inset">
  <div class="mdui-toolbar mdui-color-theme">
    <a href="javascript:;" class="mdui-btn mdui-btn-icon" mdui-drawer="{target: '#sidebar', swipe: true}"><i class="mdui-icon material-icons">menu</i></a>
    <a href="/" class="mdui-typo-headline">龙之叶的博客</a>
    <div class="mdui-toolbar-spacer"></div>
    <a href="javascript:;" class="mdui-btn mdui-btn-icon" mdui-dialog="{target: '#search'}" mdui-tooltip="{content: '搜索'}"><i class="mdui-icon material-icons">search</i></a>
	<!--
    <a href="/atom.xml" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: 'RSS'}"><i class="mdui-icon material-icons">rss_feed</i></a>
	-->
  </div>
</header>
<div class="mdui-dialog" id="search">
  
    <div class="search-form">
      <input type="search" class="search-form-input" placeholder="请输入关键字">
    </div>
    <div class="search-result" data-resource="/search.xml"></div>
  
</div>

  <aside id="sidebar" class="mdui-drawer mdui-drawer-full-height">
  <script>var a=localStorage.getItem("mdui-drawer-close");if(a){document.getElementById("sidebar").className+=" mdui-drawer-close"};</script>
  <div class="mdui-grid-tile">
    <img src="/images/banner.png" style="height: 160px;">
    <img src="/images/avatar.png" class="avatar-animation" style="position: absolute; top: 10%; left: 24px; width: 64px; height: 64px; border: 2px solid #fff; border-radius: 50%;background-color:#fff;">
    <div class="mdui-grid-tile-actions">
      <div class="mdui-grid-tile-text">
        <div class="mdui-grid-tile-title">龙之叶</div>
        <div class="mdui-grid-tile-subtitle"><i class="mdui-icon material-icons">art_track</i>生命不息，折腾不止</div>
      </div>
      
        <div class="mdui-grid-tile-buttons">
          <a href="mailto:longzhiye163@163.com" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: 'longzhiye163@163.com'}"><i class="mdui-icon material-icons">email</i></a>
        </div>
      
    </div>
  </div>

  <div class="mdui-list" mdui-collapse="{accordion: true}">
    <a href="/" class="mdui-list-item mdui-ripple">
      <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-blue">home</i>
      <div class="mdui-list-item-content">主页</div>
    </a>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-0");if(a){document.getElementsByClassName("mdui-collapse-item")[0].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-deep-orange">archive</i>
        <div class="mdui-list-item-content">归档</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/archives/2025/07/">七月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/06/">六月 2025<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/03/">三月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/02/">二月 2025<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/01/">一月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/10/">十月 2024<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/09/">九月 2024<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/08/">八月 2024<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/03/">三月 2024<span class="mdui-ripple sidebar_archives-count">5</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/02/">二月 2024<span class="mdui-ripple sidebar_archives-count">11</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/01/">一月 2024<span class="mdui-ripple sidebar_archives-count">9</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/12/">十二月 2023<span class="mdui-ripple sidebar_archives-count">10</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/11/">十一月 2023<span class="mdui-ripple sidebar_archives-count">8</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/10/">十月 2023<span class="mdui-ripple sidebar_archives-count">8</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/09/">九月 2023<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/08/">八月 2023<span class="mdui-ripple sidebar_archives-count">6</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/06/">六月 2023<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/05/">五月 2023<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/04/">四月 2023<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/03/">三月 2023<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/02/">二月 2023<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2022/09/">九月 2022<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2022/08/">八月 2022<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/04/">四月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/03/">三月 2017<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/02/">二月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/01/">一月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/12/">十二月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/11/">十一月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/10/">十月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/08/">八月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a>
        
      </div>
    </div>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-1");if(a){document.getElementsByClassName("mdui-collapse-item")[1].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-green">class</i>
        <div class="mdui-list-item-content">分类</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术<span class="mdui-ripple sidebar_archives-count">98</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E7%94%9F%E6%B4%BB/">生活<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E8%B5%84%E8%AE%AF/">资讯<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E9%80%9A%E7%9F%A5/">通知<span class="mdui-ripple sidebar_archives-count">4</span></a>
        
      </div>
    </div>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-2");if(a){document.getElementsByClassName("mdui-collapse-item")[2].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-brown">bookmark</i>
        <div class="mdui-list-item-content">标签</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/tags/ANR/" rel="tag">ANR<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/APP/" rel="tag">APP<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android/" rel="tag">Android<span class="mdui-ripple sidebar_archives-count">89</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android12/" rel="tag">Android12<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android13/" rel="tag">Android13<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android14/" rel="tag">Android14<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/AndroidStudio/" rel="tag">AndroidStudio<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/AutoDraw/" rel="tag">AutoDraw<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Crash/" rel="tag">Crash<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Foxmail/" rel="tag">Foxmail<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Framework/" rel="tag">Framework<span class="mdui-ripple sidebar_archives-count">20</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/GPS%E8%BD%A8%E8%BF%B9%E5%9B%BE/" rel="tag">GPS轨迹图<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Git/" rel="tag">Git<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/GitHub/" rel="tag">GitHub<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Google/" rel="tag">Google<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Hexo/" rel="tag">Hexo<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Java/" rel="tag">Java<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Kernel/" rel="tag">Kernel<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Launcher/" rel="tag">Launcher<span class="mdui-ripple sidebar_archives-count">17</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Lib/" rel="tag">Lib<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Linux/" rel="tag">Linux<span class="mdui-ripple sidebar_archives-count">18</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Markdown/" rel="tag">Markdown<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Material-Design/" rel="tag">Material Design<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/OS-X/" rel="tag">OS X<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/OTA/" rel="tag">OTA<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/QuickTime/" rel="tag">QuickTime<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/SSH/" rel="tag">SSH<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Settings/" rel="tag">Settings<span class="mdui-ripple sidebar_archives-count">6</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/SystemUI/" rel="tag">SystemUI<span class="mdui-ripple sidebar_archives-count">19</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Ubuntu/" rel="tag">Ubuntu<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/WPS/" rel="tag">WPS<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Wifi/" rel="tag">Wifi<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/WindTerm/" rel="tag">WindTerm<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Windows/" rel="tag">Windows<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/androidmk/" rel="tag">androidmk<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/blog/" rel="tag">blog<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/build/" rel="tag">build<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/feel/" rel="tag">feel<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/framework/" rel="tag">framework<span class="mdui-ripple sidebar_archives-count">50</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/git/" rel="tag">git<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/inotify/" rel="tag">inotify<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/life/" rel="tag">life<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/ninja/" rel="tag">ninja<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/rsync/" rel="tag">rsync<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/standard/" rel="tag">standard<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/test/" rel="tag">test<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1/" rel="tag">企业微信<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" rel="tag">操作系统<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%B5%8B%E8%AF%95/" rel="tag">测试<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%BA%90%E7%A0%81/" rel="tag">源码<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E7%94%9F%E6%B4%BB%E6%84%9F%E6%82%9F/" rel="tag">生活感悟<span class="mdui-ripple sidebar_archives-count">1</span></a>
        
      </div>
    </div>
    <a href="/about" class="mdui-list-item mdui-ripple">
      <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-purple">person</i>
      <div class="mdui-list-item-content">关于</div>
    </a>
  </div>

  <div class="mdui-divider"></div>

  <div class="mdui-list" mdui-collapse="{accordion: true}">
    
      <a href="/timeline" class="mdui-list-item mdui-ripple">时间轴</a>
    
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-3");if(a){document.getElementsByClassName("mdui-collapse-item")[3].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <div class="mdui-list-item-content">友情链接</div>
        <i class="mdui-list-item-icon mdui-icon material-icons">link</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
          <a href="http://www.niemingzhao.top" target="_blank" class="mdui-list-item mdui-p-l-2 mdui-text-color-theme-accent mdui-ripple" style="justify-content: center;">聂明照的博客</a>
        
        
      </div>
    </div>
  </div>
</aside>

  <main id="main" class="mdui-m-t-5 fadeIn animated">
  
<link rel="stylesheet" href="//cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css">

  <style>#main article .mdui-card-content .center-block{display:block!important;margin-right:auto!important;margin-left:auto!important}</style>
  <style>#main article .mdui-card-content .text-center{text-align:center!important}</style>
  <article class="mdui-card mdui-m-b-5">
    <header class="mdui-card-media">
      <img src="/images/random/material-7.png" style="max-height: 240px;">
      <div class="mdui-card-media-covered">
        <div class="mdui-card-primary">
          <div class="mdui-card-primary-title">Android 14 平板Taskbar加载流程解析</div>
          <div class="mdui-card-primary-subtitle"><i class="iconfont">&#xe697;</i> 2024-02-12 / <i class="iconfont">&#xe601;</i> 龙之叶 &nbsp;&nbsp; <span id="busuanzi_container_page_pv" style="display: none;"><i class="iconfont">&#xe7fd;</i> <span id="busuanzi_value_page_pv"></span></span></div>
        </div>
      </div>
      <div class="mdui-card-menu">
        
          <button class="mdui-btn mdui-btn-icon mdui-text-color-white" mdui-menu="{target: '#qrcode', align: 'right'}"><i class="mdui-icon material-icons">devices</i></button>
          <ul class="mdui-menu" id="qrcode">
            
              <li class="mdui-menu-item"><a class="mdui-text-center mdui-ripple">发送到手机</a></li>
            
            <li class="mdui-menu-item" disabled>
              
                <img src="//qr.liantu.com/api.php?w=246&m=10&text=http://longzhiye.top/2024/02/12/2024-02-12/">
              
            </li>
          </ul>
        
        
          <button class="mdui-btn mdui-btn-icon mdui-text-color-white" mdui-menu="{target: '#share_menu', align: 'right'}"><i class="mdui-icon material-icons">share</i></button>
          <ul class="mdui-menu" id="share_menu">
            <li class="mdui-menu-item">
              <a href="https://service.weibo.com/share/share.php?appkey=&title=Android 14 平板Taskbar加载流程解析&url=http://longzhiye.top/2024/02/12/2024-02-12/&pic=http://longzhiye.top/images/favicon.png&searchPic=false&style=simple" target="_blank" class="mdui-ripple">分享到 Weibo</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://twitter.com/intent/tweet?text=Android 14 平板Taskbar加载流程解析&url=http://longzhiye.top/2024/02/12/2024-02-12/&via=龙之叶" target="_blank" class="mdui-ripple">分享到 Twitter</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://www.facebook.com/sharer/sharer.php?u=http://longzhiye.top/2024/02/12/2024-02-12/" target="_blank" class="mdui-ripple">分享到 Facebook</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://plus.google.com/share?url=http://longzhiye.top/2024/02/12/2024-02-12/" target="_blank" class="mdui-ripple">分享到 Google+</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://www.linkedin.com/shareArticle?mini=true&url=http://longzhiye.top/2024/02/12/2024-02-12/&title=Android 14 平板Taskbar加载流程解析" target="_blank" class="mdui-ripple">分享到 LinkedIn</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://connect.qq.com/widget/shareqq/index.html?site=龙之叶的博客&title=Android 14 平板Taskbar加载流程解析&pics=http://longzhiye.top/images/favicon.png&url=http://longzhiye.top/2024/02/12/2024-02-12/" target="_blank" class="mdui-ripple">分享到 QQ</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://telegram.me/share/url?url=http://longzhiye.top/2024/02/12/2024-02-12/&text=Android 14 平板Taskbar加载流程解析" target="_blank" class="mdui-ripple">分享到 Telegram</a>
            </li>
          </ul>
        
      </div>
    </header>
    <div class="mdui-card-content mdui-typo">
      <h3 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h3><p>从 Android 12开始，如果是大屏底下导航栏会变成显示一个任务栏，从 <strong>NavigationBar</strong> 变成 <strong>Taskbar</strong> 。</p>
<blockquote>
<p>注：<strong>CentralSurfacesImpl.java</strong> 与 原来的 <strong>statusbar.java</strong> 的作用一样。</p>
</blockquote>
<p><strong>CentralSurfacesImpl</strong> 的启动流程前面有说过，这里不在说明。</p>
<p><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">CentralSurfacesImpl</span> <span class="keyword">extends</span> <span class="title class_">CoreStartable</span> <span class="keyword">implements</span></span><br><span class="line">        <span class="title class_">CentralSurfaces</span> &#123;</span><br><span class="line"></span><br><span class="line">     <span class="comment">//省略其他代码....</span></span><br><span class="line">    <span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">makeStatusBarView</span><span class="params">(<span class="meta">@Nullable</span> RegisterStatusBarResult result)</span> &#123;</span><br><span class="line">        <span class="comment">//省略其他代码....</span></span><br><span class="line">        createNavigationBar(result);</span><br><span class="line">       <span class="comment">//省略其他代码....</span></span><br><span class="line">  </span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">createNavigationBar</span><span class="params">(<span class="meta">@Nullable</span> RegisterStatusBarResult result)</span> &#123;</span><br><span class="line">        <span class="comment">// 调用 NavigationBarController 的 createNavigationBars()方法创建 NavigationBar</span></span><br><span class="line">        mNavigationBarController.createNavigationBars(<span class="literal">true</span> <span class="comment">/* includeDefaultDisplay */</span>, result);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>接着往下看：<br><strong>NavigationBarController#createNavigationBars()</strong><br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">createNavigationBars</span><span class="params">(<span class="keyword">final</span> <span class="type">boolean</span> includeDefaultDisplay,</span></span><br><span class="line"><span class="params">        RegisterStatusBarResult result)</span> &#123;</span><br><span class="line">    <span class="comment">// 如果需要，更新辅助功能按钮模式</span></span><br><span class="line">    updateAccessibilityButtonModeIfNeeded();</span><br><span class="line">    <span class="comment">// 这里是重点，Android 12 之前版本的，没有这个判断。可以看下 initializeTaskbarIfNecessary() 方法。</span></span><br><span class="line">    <span class="comment">// 如果我们初始化TaskBar，则不需要在默认显示上创建导航栏</span></span><br><span class="line">    <span class="keyword">final</span> <span class="type">boolean</span> <span class="variable">shouldCreateDefaultNavbar</span> <span class="operator">=</span> includeDefaultDisplay</span><br><span class="line">            &amp;&amp; !initializeTaskbarIfNecessary();</span><br><span class="line">    Display[] displays = mDisplayManager.getDisplays();</span><br><span class="line">    <span class="keyword">for</span> (Display display : displays) &#123;</span><br><span class="line">        <span class="keyword">if</span> (shouldCreateDefaultNavbar || display.getDisplayId() != DEFAULT_DISPLAY) &#123;</span><br><span class="line">            createNavigationBar(display, <span class="literal">null</span> <span class="comment">/* savedState */</span>, result);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/** <span class="doctag">@return</span> &#123;<span class="doctag">@code</span> true&#125; if taskbar is enabled, false otherwise */</span></span><br><span class="line"><span class="keyword">private</span> <span class="type">boolean</span> <span class="title function_">initializeTaskbarIfNecessary</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="comment">// 这里会判断是否是平板。</span></span><br><span class="line">    <span class="comment">// 跟踪代码发现，如果屏幕的（最小边长度*160/dpi值）&lt; 600，就会判断为设备是平板设备</span></span><br><span class="line">    <span class="comment">// system/vendor/mediatek/proprietary/packages/apps/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java</span></span><br><span class="line">    <span class="comment">// Enable for large screens or (phone AND flag is set); assuming phone = !mIsLargeScreen</span></span><br><span class="line">    <span class="type">boolean</span> <span class="variable">taskbarEnabled</span> <span class="operator">=</span> (mIsLargeScreen || mFeatureFlags.isEnabled(</span><br><span class="line">            Flags.HIDE_NAVBAR_WINDOW)) &amp;&amp; shouldCreateNavBarAndTaskBar(mContext.getDisplayId());</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (taskbarEnabled) &#123;</span><br><span class="line">        Trace.beginSection(<span class="string">&quot;NavigationBarController#initializeTaskbarIfNecessary&quot;</span>);</span><br><span class="line">        <span class="keyword">final</span> <span class="type">int</span> <span class="variable">displayId</span> <span class="operator">=</span> mContext.getDisplayId();</span><br><span class="line">        <span class="comment">// Hint to NavBarHelper if we are replacing an existing bar to skip extra work</span></span><br><span class="line">        mNavBarHelper.setTogglingNavbarTaskbar(mNavigationBars.contains(displayId));</span><br><span class="line">        <span class="comment">// Remove navigation bar when taskbar is showing</span></span><br><span class="line">        <span class="comment">// 移除导航栏</span></span><br><span class="line">        removeNavigationBar(displayId);</span><br><span class="line">        <span class="comment">// 加载任务栏</span></span><br><span class="line">        mTaskbarDelegate.init(displayId);</span><br><span class="line">        mNavBarHelper.setTogglingNavbarTaskbar(<span class="literal">false</span>);</span><br><span class="line">        Trace.endSection();</span><br><span class="line"></span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        mTaskbarDelegate.destroy();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> taskbarEnabled;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>我们分析平板，所以这里直接看  <strong>mTaskbarDelegate.init(mContext.getDisplayId())</strong> 方法；<br><strong>TaskbarDelegate#init()</strong><br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/TaskbarDelegate.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">init</span><span class="params">(<span class="type">int</span> displayId)</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> (mInitialized) &#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//省略其他代码....</span></span><br><span class="line">    <span class="comment">// 注册监听，切换导航模式时接收回调。</span></span><br><span class="line">    mEdgeBackGestureHandler.onNavigationModeChanged(</span><br><span class="line">            mNavigationModeController.addListener(<span class="built_in">this</span>));</span><br><span class="line">    <span class="comment">// 边缘手势处理，注意：这里只加载、处理手势。</span></span><br><span class="line">    <span class="comment">// 手势中左右两返回图标由这里加载，底部黑色小横条不在这里加载。</span></span><br><span class="line">    mEdgeBackGestureHandler.onNavBarAttached();</span><br><span class="line">    <span class="comment">//省略其他代码....</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 导航模式改变回调，进行处理</span></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onNavigationModeChanged</span><span class="params">(<span class="type">int</span> mode)</span> &#123;</span><br><span class="line">    mNavigationMode = mode;</span><br><span class="line">    mEdgeBackGestureHandler.onNavigationModeChanged(mode);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="1-手势加载"><a href="#1-手势加载" class="headerlink" title="1. 手势加载"></a>1. 手势加载</h4><p><strong>EdgeBackGestureHandler#onNavBarAttached()</strong><br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@see</span> NavigationBarView#onAttachedToWindow()</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onNavBarAttached</span><span class="params">()</span> &#123;</span><br><span class="line">    mIsAttached = <span class="literal">true</span>;</span><br><span class="line">    mProtoTracer.add(<span class="built_in">this</span>);</span><br><span class="line">    mOverviewProxyService.addCallback(mQuickSwitchListener);</span><br><span class="line">    mSysUiState.addCallback(mSysUiStateCallback);</span><br><span class="line">    <span class="comment">// 重点关注这里，更新视图</span></span><br><span class="line">    updateIsEnabled();</span><br><span class="line">    startTracking();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">updateIsEnabled</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="comment">// mIsAttached 是否已经添加上了，mIsGesturalModeEnabled 是否启用手势模式</span></span><br><span class="line">    <span class="type">boolean</span> <span class="variable">isEnabled</span> <span class="operator">=</span> mIsAttached &amp;&amp; mIsGesturalModeEnabled;</span><br><span class="line">    <span class="keyword">if</span> (isEnabled == mIsEnabled) &#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    mIsEnabled = isEnabled;</span><br><span class="line">    <span class="comment">// 如果无效的话结束监听 Input</span></span><br><span class="line">    disposeInputChannel();</span><br><span class="line">    <span class="keyword">if</span> (mEdgeBackPlugin != <span class="literal">null</span>) &#123;</span><br><span class="line">        <span class="comment">// 边缘导航栏销毁</span></span><br><span class="line">        mEdgeBackPlugin.onDestroy();</span><br><span class="line">        mEdgeBackPlugin = <span class="literal">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 是否启用手势模式</span></span><br><span class="line">    <span class="keyword">if</span> (!mIsEnabled) &#123;</span><br><span class="line">            <span class="comment">// 注销监听返回手势参数的设置变化</span></span><br><span class="line">        mGestureNavigationSettingsObserver.unregister();</span><br><span class="line">        <span class="keyword">if</span> (DEBUG_MISSING_GESTURE) &#123;</span><br><span class="line">            Log.d(DEBUG_MISSING_GESTURE_TAG, <span class="string">&quot;Unregister display listener&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        mPluginManager.removePluginListener(<span class="built_in">this</span>);</span><br><span class="line">        TaskStackChangeListeners.getInstance().unregisterTaskStackListener(mTaskStackListener);</span><br><span class="line">        DeviceConfig.removeOnPropertiesChangedListener(mOnPropertiesChangedListener);</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">                <span class="comment">// 注销 WMS 里保存的除外区域监听</span></span><br><span class="line">            mWindowManagerService.unregisterSystemGestureExclusionListener(</span><br><span class="line">                    mGestureExclusionListener, mDisplayId);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (RemoteException | IllegalArgumentException e) &#123;</span><br><span class="line">            Log.e(TAG, <span class="string">&quot;Failed to unregister window manager callbacks&quot;</span>, e);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="comment">// 监听返回手势参数的设置变化</span></span><br><span class="line">        mGestureNavigationSettingsObserver.register();</span><br><span class="line">        updateDisplaySize();</span><br><span class="line">        <span class="keyword">if</span> (DEBUG_MISSING_GESTURE) &#123;</span><br><span class="line">            Log.d(DEBUG_MISSING_GESTURE_TAG, <span class="string">&quot;Register display listener&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        TaskStackChangeListeners.getInstance().registerTaskStackListener(mTaskStackListener);</span><br><span class="line">        DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_SYSTEMUI,</span><br><span class="line">                mMainExecutor::execute, mOnPropertiesChangedListener);</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="comment">// 监听 WMS 里保存的除外区域</span></span><br><span class="line">            mWindowManagerService.registerSystemGestureExclusionListener(</span><br><span class="line">                    mGestureExclusionListener, mDisplayId);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (RemoteException | IllegalArgumentException e) &#123;</span><br><span class="line">            Log.e(TAG, <span class="string">&quot;Failed to register window manager callbacks&quot;</span>, e);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//  注册名为 edge-swipe 的InputMonitor</span></span><br><span class="line">        mInputMonitor = InputManager.getInstance().monitorGestureInput(</span><br><span class="line">                <span class="string">&quot;edge-swipe&quot;</span>, mDisplayId);</span><br><span class="line">        mInputEventReceiver = <span class="keyword">new</span> <span class="title class_">InputChannelCompat</span>.InputEventReceiver(</span><br><span class="line">                mInputMonitor.getInputChannel(), Looper.getMainLooper(),</span><br><span class="line">                Choreographer.getInstance(), <span class="built_in">this</span>::onInputEvent);</span><br><span class="line">        <span class="comment">// 添加 NavigationBarEdgePanel 为 Edge Back 事件的处理实现</span></span><br><span class="line">        setEdgeBackPlugin(</span><br><span class="line">                <span class="keyword">new</span> <span class="title class_">NavigationBarEdgePanel</span>(mContext, mBackAnimation, mLatencyTracker));</span><br><span class="line">        mPluginManager.addPluginListener(</span><br><span class="line">                <span class="built_in">this</span>, NavigationEdgeBackPlugin.class, <span class="comment">/*allowMultiple=*/</span> <span class="literal">false</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 更新 ML 模型资源.</span></span><br><span class="line">    updateMLModelState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 创建返回手势视图</span></span><br><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">setEdgeBackPlugin</span><span class="params">(NavigationEdgeBackPlugin edgeBackPlugin)</span> &#123;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        Trace.beginSection(<span class="string">&quot;setEdgeBackPlugin&quot;</span>);</span><br><span class="line">        <span class="comment">// 缓存 NavigationEdgeBackPlugin 实现</span></span><br><span class="line">        mEdgeBackPlugin = edgeBackPlugin;</span><br><span class="line">        <span class="comment">// 向 NavigationEdgeBackPlugin 注册 Back 手势的触发回调</span></span><br><span class="line">        mEdgeBackPlugin.setBackCallback(mBackCallback);</span><br><span class="line">        <span class="comment">// 准备好手势视图的 Window 参数</span></span><br><span class="line">        mEdgeBackPlugin.setLayoutParams(createLayoutParams());</span><br><span class="line">        updateDisplaySize();</span><br><span class="line">    &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">        Trace.endSection();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 配置返回手势 Window 的参数</span></span><br><span class="line"><span class="comment">// 包括 flag、type、title 等属性</span></span><br><span class="line"><span class="keyword">private</span> WindowManager.LayoutParams <span class="title function_">createLayoutParams</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">Resources</span> <span class="variable">resources</span> <span class="operator">=</span> mContext.getResources();</span><br><span class="line">    WindowManager.<span class="type">LayoutParams</span> <span class="variable">layoutParams</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">WindowManager</span>.LayoutParams(</span><br><span class="line">            resources.getDimensionPixelSize(R.dimen.navigation_edge_panel_width),</span><br><span class="line">            resources.getDimensionPixelSize(R.dimen.navigation_edge_panel_height),</span><br><span class="line">            WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,</span><br><span class="line">            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE</span><br><span class="line">                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE</span><br><span class="line">                    | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,</span><br><span class="line">            PixelFormat.TRANSLUCENT);</span><br><span class="line">    ...</span><br><span class="line">    layoutParams.setTitle(TAG + mContext.getDisplayId());</span><br><span class="line">    layoutParams.setFitInsetsTypes(<span class="number">0</span> <span class="comment">/* types */</span>);</span><br><span class="line">    layoutParams.setTrustedOverlay();</span><br><span class="line">    <span class="keyword">return</span> layoutParams;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>到此手势导航创建完成。</p>
<blockquote>
<p>注意：此时 View 还是不可见的，后续事件产生的时候会进行展示和刷新</p>
</blockquote>
<p>下面粗略的看下手势相关的事件：<br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">onMotionEvent</span><span class="params">(MotionEvent ev)</span> &#123;</span><br><span class="line">    <span class="type">int</span> <span class="variable">action</span> <span class="operator">=</span> ev.getActionMasked();</span><br><span class="line">    <span class="keyword">if</span> (action == MotionEvent.ACTION_DOWN) &#123;</span><br><span class="line">        mInputEventReceiver.setBatchingEnabled(<span class="literal">false</span>);</span><br><span class="line">        mIsOnLeftEdge = ev.getX() &lt;= mEdgeWidthLeft + mLeftInset;</span><br><span class="line">        mMLResults = <span class="number">0</span>;</span><br><span class="line">        mLogGesture = <span class="literal">false</span>;</span><br><span class="line">        mInRejectedExclusion = <span class="literal">false</span>;</span><br><span class="line">        <span class="type">boolean</span> <span class="variable">isWithinInsets</span> <span class="operator">=</span> isWithinInsets((<span class="type">int</span>) ev.getX(), (<span class="type">int</span>) ev.getY());</span><br><span class="line">        <span class="comment">// 根据返回手势是否有效、</span></span><br><span class="line">        <span class="comment">// 点击区域是否是停用区域等条件</span></span><br><span class="line">        <span class="comment">// 得到当前是否允许视图处理该手势</span></span><br><span class="line">        mAllowGesture = !mDisabledForQuickstep &amp;&amp; mIsBackGestureAllowed &amp;&amp; isWithinInsets</span><br><span class="line">                &amp;&amp; !mGestureBlockingActivityRunning</span><br><span class="line">                &amp;&amp; !QuickStepContract.isBackGestureDisabled(mSysUiFlags)</span><br><span class="line">                &amp;&amp; isWithinTouchRegion((<span class="type">int</span>) ev.getX(), (<span class="type">int</span>) ev.getY());</span><br><span class="line">        <span class="keyword">if</span> (mAllowGesture) &#123;</span><br><span class="line">            <span class="comment">// 更新当前是屏幕左侧还是右侧</span></span><br><span class="line">            mEdgeBackPlugin.setIsLeftPanel(mIsOnLeftEdge);</span><br><span class="line">            <span class="comment">// 发射事件给视图</span></span><br><span class="line">            mEdgeBackPlugin.onMotionEvent(ev);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (mAllowGesture || mLogGesture) &#123;</span><br><span class="line">        <span class="keyword">if</span> (!mThresholdCrossed) &#123;</span><br><span class="line">            mEndPoint.x = (<span class="type">int</span>) ev.getX();</span><br><span class="line">            mEndPoint.y = (<span class="type">int</span>) ev.getY();</span><br><span class="line">            <span class="comment">// 多个手指按下的话取消事件处理</span></span><br><span class="line">            <span class="keyword">if</span> (action == MotionEvent.ACTION_POINTER_DOWN) &#123;</span><br><span class="line">                <span class="keyword">if</span> (mAllowGesture) &#123;</span><br><span class="line">                    logGesture(SysUiStatsLog.BACK_GESTURE__TYPE__INCOMPLETE_MULTI_TOUCH);</span><br><span class="line">                    cancelGesture(ev);</span><br><span class="line">                &#125;</span><br><span class="line">                mLogGesture = <span class="literal">false</span>;</span><br><span class="line">                <span class="keyword">return</span>;</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (action == MotionEvent.ACTION_MOVE) &#123;</span><br><span class="line">                <span class="comment">// 手指移动超过长按阈值的话</span></span><br><span class="line">                <span class="comment">// 也要取消事件处理</span></span><br><span class="line">                <span class="keyword">if</span> ((ev.getEventTime() - ev.getDownTime()) &gt; mLongPressTimeout) &#123;</span><br><span class="line">                    <span class="keyword">if</span> (mAllowGesture) &#123;</span><br><span class="line">                        logGesture(SysUiStatsLog.BACK_GESTURE__TYPE__INCOMPLETE_LONG_PRESS);</span><br><span class="line">                        cancelGesture(ev);</span><br><span class="line">                    &#125;</span><br><span class="line">                    mLogGesture = <span class="literal">false</span>;</span><br><span class="line">                    <span class="keyword">return</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                ...</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 通过上述检查的话</span></span><br><span class="line">        <span class="comment">// 将 MOVE、UP 交给视图</span></span><br><span class="line">        <span class="keyword">if</span> (mAllowGesture) &#123;</span><br><span class="line">            <span class="comment">// forward touch</span></span><br><span class="line">            mEdgeBackPlugin.onMotionEvent(ev);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    mProtoTracer.scheduleFrameUpdate();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>事件间传递到 <strong>NavigationBarEdgePanel</strong> ，进行展示返回手势和触发返回。<br><strong>NavigationBarEdgePanel</strong> 继续进行后面的工作：手势的判断、视图的刷新、动画的展示。<br><strong>onMotionEvent()</strong> 的逻辑：</p>
<ul>
<li><strong>DOWN</strong> 的时候先让视图变为可见 VISIBLE</li>
<li><strong>MOVE</strong> 的处理通过 <strong>handleMoveEvent()</strong> 判断距离，决定是否要更新赋予 mTriggerBack</li>
<li><strong>UP</strong> 的时候将检查该变量决定是否触发返回动作即 <strong>triggerBack()</strong></li>
</ul>
<p><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/NavigationBarEdgePanel.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onMotionEvent</span><span class="params">(MotionEvent event)</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> (mVelocityTracker == <span class="literal">null</span>) &#123;</span><br><span class="line">        mVelocityTracker = VelocityTracker.obtain();</span><br><span class="line">    &#125;</span><br><span class="line">    mVelocityTracker.addMovement(event);</span><br><span class="line">    <span class="keyword">switch</span> (event.getActionMasked()) &#123;</span><br><span class="line">        <span class="keyword">case</span> MotionEvent.ACTION_DOWN:</span><br><span class="line">            mDragSlopPassed = <span class="literal">false</span>;</span><br><span class="line">            resetOnDown();</span><br><span class="line">            mStartX = event.getX();</span><br><span class="line">            mStartY = event.getY();</span><br><span class="line">            setVisibility(VISIBLE);</span><br><span class="line">            updatePosition(event.getY());</span><br><span class="line">            mRegionSamplingHelper.start(mSamplingRect);</span><br><span class="line">            mWindowManager.updateViewLayout(<span class="built_in">this</span>, mLayoutParams);</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> MotionEvent.ACTION_MOVE:</span><br><span class="line">            handleMoveEvent(event);</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> MotionEvent.ACTION_UP:</span><br><span class="line">            <span class="keyword">if</span> (mTriggerBack) &#123;</span><br><span class="line">                triggerBack();</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                cancelBack();</span><br><span class="line">            &#125;</span><br><span class="line">            ...</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>手势相关的事件流程到此打住了。</p>
<h4 id="2-按钮导航"><a href="#2-按钮导航" class="headerlink" title="2. 按钮导航"></a>2. 按钮导航</h4><p>按钮导航是在 <strong>TouchInteractionService.java</strong> 中的 <strong>onCreate()</strong> 方法开始的。<br><strong>packages/apps/Launcher3/quickstep/src/com/android/quickstep/TouchInteractionService.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onCreate</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="built_in">super</span>.onCreate();</span><br><span class="line">    <span class="comment">//省略其他代码....</span></span><br><span class="line">    </span><br><span class="line">    mTaskbarManager = <span class="keyword">new</span> <span class="title class_">TaskbarManager</span>(<span class="built_in">this</span>);</span><br><span class="line">    <span class="comment">//省略其他代码....</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>用户配置完成后，根据配置，是否加载按钮导航。如果加载则会调用 <strong>TaskbarManager.java</strong> 中的 <strong>recreateTaskbar()</strong> 方法。<br><strong>TaskbarManager#recreateTaskbar()</strong><br><strong>packages/apps/Launcher3/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">recreateTaskbar</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="comment">// 销毁现有任务栏</span></span><br><span class="line">    destroyExistingTaskbar();</span><br><span class="line">    <span class="comment">// 获取设备配置文件的</span></span><br><span class="line">    <span class="type">DeviceProfile</span> <span class="variable">dp</span> <span class="operator">=</span></span><br><span class="line">            mUserUnlocked ? LauncherAppState.getIDP(mContext).getDeviceProfile(mContext) : <span class="literal">null</span>;</span><br><span class="line">    <span class="comment">// 任务栏是否启用</span></span><br><span class="line">    <span class="type">boolean</span> <span class="variable">isTaskBarEnabled</span> <span class="operator">=</span> dp != <span class="literal">null</span> &amp;&amp; dp.isTaskbarPresent;</span><br><span class="line">    <span class="keyword">if</span>(dp != <span class="literal">null</span>)&#123;</span><br><span class="line">        Log.d(<span class="string">&quot;longzhiye&quot;</span>,<span class="string">&quot;longzhiye&quot;</span>+(dp != <span class="literal">null</span>)+<span class="string">&quot;----&quot;</span>+(dp.isTaskbarPresent));</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (!isTaskBarEnabled) &#123;</span><br><span class="line">        SystemUiProxy.INSTANCE.get(mContext)</span><br><span class="line">                .notifyTaskbarStatus(<span class="comment">/* visible */</span> <span class="literal">false</span>, <span class="comment">/* stashed */</span> <span class="literal">false</span>);</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// TaskbarActivityContext 按钮导航的视图在里面加载，包括那个底部横线也在里面。</span></span><br><span class="line">    mTaskbarActivityContext = <span class="keyword">new</span> <span class="title class_">TaskbarActivityContext</span>(mContext, dp, mNavButtonController,</span><br><span class="line">            mUnfoldProgressProvider);</span><br><span class="line">    <span class="comment">// 初始化</span></span><br><span class="line">    mTaskbarActivityContext.init(mSharedState);</span><br><span class="line">    <span class="keyword">if</span> (mActivity != <span class="literal">null</span>) &#123;</span><br><span class="line">        <span class="comment">// 设置相关控制器</span></span><br><span class="line">        mTaskbarActivityContext.setUIController(</span><br><span class="line">                createTaskbarUIControllerForActivity(mActivity));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在 <strong>TaskbarManager</strong> 类中有个 <strong>mDispInfoChangeListener</strong> 的监听，当导航模式切换时，会在 <strong>DisplayController</strong> 类中 去回调这里来。<br>接着往下看TaskbarActivityContext的构造方法：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="title function_">TaskbarActivityContext</span><span class="params">(Context windowContext, DeviceProfile dp,</span></span><br><span class="line"><span class="params">        TaskbarNavButtonController buttonController, ScopedUnfoldTransitionProgressProvider</span></span><br><span class="line"><span class="params">        unfoldTransitionProgressProvider)</span> &#123;</span><br><span class="line">    <span class="built_in">super</span>(windowContext);</span><br><span class="line">    mDeviceProfile = dp.copy(<span class="built_in">this</span>);</span><br><span class="line">    <span class="keyword">final</span> <span class="type">Resources</span> <span class="variable">resources</span> <span class="operator">=</span> getResources();</span><br><span class="line">    mNavMode = DisplayController.getNavigationMode(windowContext);</span><br><span class="line">    mImeDrawsImeNavBar = getBoolByName(IME_DRAWS_IME_NAV_BAR_RES_NAME, resources, <span class="literal">false</span>);</span><br><span class="line">    mIsSafeModeEnabled = TraceHelper.allowIpcs(<span class="string">&quot;isSafeMode&quot;</span>,</span><br><span class="line">            () -&gt; getPackageManager().isSafeMode());</span><br><span class="line">    mIsUserSetupComplete = SettingsCache.INSTANCE.get(<span class="built_in">this</span>).getValue(</span><br><span class="line">            Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE), <span class="number">0</span>);</span><br><span class="line">    mIsNavBarForceVisible = SettingsCache.INSTANCE.get(<span class="built_in">this</span>).getValue(</span><br><span class="line">            Settings.Secure.getUriFor(Settings.Secure.NAV_BAR_KIDS_MODE), <span class="number">0</span>);</span><br><span class="line">    mIsNavBarKidsMode = SettingsCache.INSTANCE.get(<span class="built_in">this</span>).getValue(</span><br><span class="line">            Settings.Secure.getUriFor(Settings.Secure.NAV_BAR_KIDS_MODE), <span class="number">0</span>);</span><br><span class="line">    updateIconSize(resources);</span><br><span class="line">    <span class="comment">// 首先获取显示和焦点，因为视图可能会在构造函数中使用它们。</span></span><br><span class="line">    <span class="type">Display</span> <span class="variable">display</span> <span class="operator">=</span> windowContext.getDisplay();</span><br><span class="line">    <span class="type">Context</span> <span class="variable">c</span> <span class="operator">=</span> display.getDisplayId() == Display.DEFAULT_DISPLAY</span><br><span class="line">            ? windowContext.getApplicationContext()</span><br><span class="line">            : windowContext.getApplicationContext().createDisplayContext(display);</span><br><span class="line">    mWindowManager = c.getSystemService(WindowManager.class);</span><br><span class="line">    mLeftCorner = display.getRoundedCorner(RoundedCorner.POSITION_BOTTOM_LEFT);</span><br><span class="line">    mRightCorner = display.getRoundedCorner(RoundedCorner.POSITION_BOTTOM_RIGHT);</span><br><span class="line">    <span class="comment">// 初始化 views.</span></span><br><span class="line">    mDragLayer = (TaskbarDragLayer) mLayoutInflater.inflate(</span><br><span class="line">            R.layout.taskbar, <span class="literal">null</span>, <span class="literal">false</span>);</span><br><span class="line">    <span class="type">TaskbarView</span> <span class="variable">taskbarView</span> <span class="operator">=</span> mDragLayer.findViewById(R.id.taskbar_view);</span><br><span class="line">    <span class="type">TaskbarScrimView</span> <span class="variable">taskbarScrimView</span> <span class="operator">=</span> mDragLayer.findViewById(R.id.taskbar_scrim);</span><br><span class="line">    <span class="type">FrameLayout</span> <span class="variable">navButtonsView</span> <span class="operator">=</span> mDragLayer.findViewById(R.id.navbuttons_view);</span><br><span class="line">    <span class="type">StashedHandleView</span> <span class="variable">stashedHandleView</span> <span class="operator">=</span> mDragLayer.findViewById(R.id.stashed_handle);</span><br><span class="line">    mAccessibilityDelegate = <span class="keyword">new</span> <span class="title class_">TaskbarShortcutMenuAccessibilityDelegate</span>(<span class="built_in">this</span>);</span><br><span class="line">    <span class="comment">// 构造控制器 controllers，将会在对应的控制添加对应的图标，以控制逻辑</span></span><br><span class="line">    mControllers = <span class="keyword">new</span> <span class="title class_">TaskbarControllers</span>(<span class="built_in">this</span>,</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">TaskbarDragController</span>(<span class="built_in">this</span>),</span><br><span class="line">            buttonController,</span><br><span class="line">            getPackageManager().hasSystemFeature(FEATURE_PC)</span><br><span class="line">                    ? <span class="keyword">new</span> <span class="title class_">DesktopNavbarButtonsViewController</span>(<span class="built_in">this</span>, navButtonsView) :     </span><br><span class="line">                    <span class="keyword">new</span> <span class="title class_">NavbarButtonsViewController</span>(<span class="built_in">this</span>, navButtonsView),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">RotationButtonController</span>(<span class="built_in">this</span>,</span><br><span class="line">                    c.getColor(R.color.taskbar_nav_icon_light_color),</span><br><span class="line">                    c.getColor(R.color.taskbar_nav_icon_dark_color),</span><br><span class="line">                    R.drawable.ic_sysbar_rotate_button_ccw_start_0,</span><br><span class="line">                    R.drawable.ic_sysbar_rotate_button_ccw_start_90,</span><br><span class="line">                    R.drawable.ic_sysbar_rotate_button_cw_start_0,</span><br><span class="line">                    R.drawable.ic_sysbar_rotate_button_cw_start_90,</span><br><span class="line">                    () -&gt; getDisplay().getRotation()),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">TaskbarDragLayerController</span>(<span class="built_in">this</span>, mDragLayer),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">TaskbarViewController</span>(<span class="built_in">this</span>, taskbarView),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">TaskbarScrimViewController</span>(<span class="built_in">this</span>, taskbarScrimView),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">TaskbarUnfoldAnimationController</span>(<span class="built_in">this</span>, unfoldTransitionProgressProvider,</span><br><span class="line">                    mWindowManager, WindowManagerGlobal.getWindowManagerService()),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">TaskbarKeyguardController</span>(<span class="built_in">this</span>),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">StashedHandleViewController</span>(<span class="built_in">this</span>, stashedHandleView),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">TaskbarStashController</span>(<span class="built_in">this</span>),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">TaskbarEduController</span>(<span class="built_in">this</span>),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">TaskbarAutohideSuspendController</span>(<span class="built_in">this</span>),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">TaskbarPopupController</span>(<span class="built_in">this</span>),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">TaskbarForceVisibleImmersiveController</span>(<span class="built_in">this</span>),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">TaskbarAllAppsController</span>(<span class="built_in">this</span>, dp),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">TaskbarInsetsController</span>(<span class="built_in">this</span>));</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">init</span><span class="params">(<span class="meta">@NonNull</span> TaskbarSharedState sharedState)</span> &#123;</span><br><span class="line">    mLastRequestedNonFullscreenHeight = getDefaultTaskbarWindowHeight();</span><br><span class="line">    mWindowLayoutParams = createDefaultWindowLayoutParams();</span><br><span class="line">    <span class="comment">//  在 TaskbarControllers控制器里，初始化前面构造方法中添加的各种控制器。</span></span><br><span class="line">    mControllers.init(sharedState);</span><br><span class="line">    updateSysuiStateFlags(sharedState.sysuiStateFlags, <span class="literal">true</span> <span class="comment">/* fromInit */</span>);</span><br><span class="line">    <span class="comment">// 生成 LayoutParams 用于将视图作为新窗口直接添加到 WindowManager</span></span><br><span class="line">    mWindowManager.addView(mDragLayer, mWindowLayoutParams);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>这里以 <strong>NavbarButtonsViewController</strong> 为例子分析：<br><strong>packages/apps/Launcher3/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Initializes the controller</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">init</span><span class="params">(TaskbarControllers controllers)</span> &#123;</span><br><span class="line">        <span class="comment">// 省略部分代码......</span></span><br><span class="line">    <span class="comment">// 强制导航按钮（特别是后退按钮）在设置向导期间可见。</span></span><br><span class="line">    <span class="type">boolean</span> <span class="variable">isInSetup</span> <span class="operator">=</span> !mContext.isUserSetupComplete();</span><br><span class="line">    <span class="type">boolean</span> <span class="variable">isInKidsMode</span> <span class="operator">=</span> mContext.isNavBarKidsModeActive();</span><br><span class="line">    <span class="type">boolean</span> <span class="variable">alwaysShowButtons</span> <span class="operator">=</span> isThreeButtonNav || isInSetup;</span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">        </span><br><span class="line">    <span class="keyword">if</span> (alwaysShowButtons) &#123;</span><br><span class="line">        <span class="comment">// 初始化按钮</span></span><br><span class="line">        initButtons(mNavButtonContainer, mEndContextualContainer,</span><br><span class="line">                mControllers.navButtonController);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">    mSeparateWindowParent.recreateControllers();</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">initButtons</span><span class="params">(ViewGroup navContainer, ViewGroup endContainer,</span></span><br><span class="line"><span class="params">        TaskbarNavButtonController navButtonController)</span> &#123;</span><br><span class="line">    <span class="comment">// back Button</span></span><br><span class="line">    mBackButton = addButton(R.drawable.ic_sysbar_back, BUTTON_BACK,</span><br><span class="line">            mNavButtonContainer, mControllers.navButtonController, R.id.back);</span><br><span class="line">    mBackButtonAlpha = <span class="keyword">new</span> <span class="title class_">MultiValueAlpha</span>(mBackButton, NUM_ALPHA_CHANNELS);</span><br><span class="line">    mBackButtonAlpha.setUpdateVisibility(<span class="literal">true</span>);</span><br><span class="line">    mPropertyHolders.add(<span class="keyword">new</span> <span class="title class_">StatePropertyHolder</span>(</span><br><span class="line">            mBackButtonAlpha.getProperty(ALPHA_INDEX_KEYGUARD_OR_DISABLE),</span><br><span class="line">            flags -&gt; &#123;</span><br><span class="line">                <span class="comment">// Show only if not disabled, and if not on the keyguard or otherwise only when</span></span><br><span class="line">                <span class="comment">// the bouncer or a lockscreen app is showing above the keyguard</span></span><br><span class="line">                <span class="type">boolean</span> <span class="variable">showingOnKeyguard</span> <span class="operator">=</span> (flags &amp; FLAG_KEYGUARD_VISIBLE) == <span class="number">0</span> ||</span><br><span class="line">                        (flags &amp; FLAG_ONLY_BACK_FOR_BOUNCER_VISIBLE) != <span class="number">0</span> ||</span><br><span class="line">                        (flags &amp; FLAG_KEYGUARD_OCCLUDED) != <span class="number">0</span>;</span><br><span class="line">                <span class="keyword">return</span> (flags &amp; FLAG_DISABLE_BACK) == <span class="number">0</span></span><br><span class="line">                        &amp;&amp; ((flags &amp; FLAG_KEYGUARD_VISIBLE) == <span class="number">0</span> || showingOnKeyguard);</span><br><span class="line">            &#125;));</span><br><span class="line">    <span class="type">boolean</span> <span class="variable">isRtl</span> <span class="operator">=</span> Utilities.isRtl(mContext.getResources());</span><br><span class="line">    mPropertyHolders.add(<span class="keyword">new</span> <span class="title class_">StatePropertyHolder</span>(mBackButton,</span><br><span class="line">            flags -&gt; (flags &amp; FLAG_IME_VISIBLE) != <span class="number">0</span> &amp;&amp; !mContext.isNavBarKidsModeActive(),</span><br><span class="line">            View.ROTATION, isRtl ? <span class="number">90</span> : -<span class="number">90</span>, <span class="number">0</span>));</span><br><span class="line">    <span class="comment">// Translate back button to be at end/start of other buttons for keyguard</span></span><br><span class="line">    <span class="type">int</span> <span class="variable">navButtonSize</span> <span class="operator">=</span> mContext.getResources().getDimensionPixelSize(</span><br><span class="line">            R.dimen.taskbar_nav_buttons_size);</span><br><span class="line">    mPropertyHolders.add(<span class="keyword">new</span> <span class="title class_">StatePropertyHolder</span>(</span><br><span class="line">            mBackButton, flags -&gt; (flags &amp; FLAG_ONLY_BACK_FOR_BOUNCER_VISIBLE) != <span class="number">0</span></span><br><span class="line">                    || (flags &amp; FLAG_KEYGUARD_VISIBLE) != <span class="number">0</span>,</span><br><span class="line">            VIEW_TRANSLATE_X, navButtonSize * (isRtl ? -<span class="number">2</span> : <span class="number">2</span>), <span class="number">0</span>));</span><br><span class="line">    <span class="comment">// home button</span></span><br><span class="line">    mHomeButton = addButton(R.drawable.ic_sysbar_home, BUTTON_HOME, navContainer,</span><br><span class="line">            navButtonController, R.id.home);</span><br><span class="line">    mHomeButtonAlpha = <span class="keyword">new</span> <span class="title class_">MultiValueAlpha</span>(mHomeButton, NUM_ALPHA_CHANNELS);</span><br><span class="line">    mHomeButtonAlpha.setUpdateVisibility(<span class="literal">true</span>);</span><br><span class="line">    mPropertyHolders.add(</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">StatePropertyHolder</span>(mHomeButtonAlpha.getProperty(</span><br><span class="line">                    ALPHA_INDEX_KEYGUARD_OR_DISABLE),</span><br><span class="line">            flags -&gt; (flags &amp; FLAG_KEYGUARD_VISIBLE) == <span class="number">0</span> &amp;&amp;</span><br><span class="line">                    (flags &amp; FLAG_DISABLE_HOME) == <span class="number">0</span>));</span><br><span class="line">    <span class="comment">// Recents button</span></span><br><span class="line">    <span class="type">View</span> <span class="variable">recentsButton</span> <span class="operator">=</span> addButton(R.drawable.ic_sysbar_recent, BUTTON_RECENTS,</span><br><span class="line">            navContainer, navButtonController, R.id.recent_apps);</span><br><span class="line">    mHitboxExtender.init(recentsButton, mNavButtonsView, mContext.getDeviceProfile(),</span><br><span class="line">            () -&gt; &#123;</span><br><span class="line">                <span class="type">float</span>[] recentsCoords = <span class="keyword">new</span> <span class="title class_">float</span>[<span class="number">2</span>];</span><br><span class="line">                getDescendantCoordRelativeToAncestor(recentsButton, mNavButtonsView,</span><br><span class="line">                        recentsCoords, <span class="literal">false</span>);</span><br><span class="line">                <span class="keyword">return</span> recentsCoords;</span><br><span class="line">            &#125;, <span class="keyword">new</span> <span class="title class_">Handler</span>());</span><br><span class="line">    recentsButton.setOnClickListener(v -&gt; &#123;</span><br><span class="line">        navButtonController.onButtonClick(BUTTON_RECENTS);</span><br><span class="line">        mHitboxExtender.onRecentsButtonClicked();</span><br><span class="line">    &#125;);</span><br><span class="line">    mPropertyHolders.add(<span class="keyword">new</span> <span class="title class_">StatePropertyHolder</span>(recentsButton,</span><br><span class="line">            flags -&gt; (flags &amp; FLAG_KEYGUARD_VISIBLE) == <span class="number">0</span> &amp;&amp; (flags &amp; FLAG_DISABLE_RECENTS) == <span class="number">0</span></span><br><span class="line">                    &amp;&amp; !mContext.isNavBarKidsModeActive()));</span><br><span class="line">    <span class="comment">// A11y button</span></span><br><span class="line">    mA11yButton =  (R.drawable.ic_sysbar_accessibility_button, BUTTON_A11Y,</span><br><span class="line">            endContainer, navButtonController, R.id.accessibility_button,</span><br><span class="line">            R.layout.taskbar_contextual_button);</span><br><span class="line">    mPropertyHolders.add(<span class="keyword">new</span> <span class="title class_">StatePropertyHolder</span>(mA11yButton,</span><br><span class="line">            flags -&gt; (flags &amp; FLAG_A11Y_VISIBLE) != <span class="number">0</span></span><br><span class="line">                    &amp;&amp; (flags &amp; FLAG_ROTATION_BUTTON_VISIBLE) == <span class="number">0</span>));</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>事件的在 <strong>addButton()</strong> 的时候直接设置了，而且有特殊需求的，会单独设置。</p>

      
      <blockquote>
        
        <strong>本文链接：</strong><br><a href="http://longzhiye.top/2024/02/12/2024-02-12/">http://longzhiye.top/2024/02/12/2024-02-12/</a>
      </blockquote>
    </div>
    <footer class="mdui-card-actions">
      
        <a class="mdui-ripple article_categories-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术</a>
      
      
        <a class="mdui-ripple article_tags-link" href="/tags/Android/" rel="tag">Android</a><a class="mdui-ripple article_tags-link" href="/tags/Launcher/" rel="tag">Launcher</a><a class="mdui-ripple article_tags-link" href="/tags/SystemUI/" rel="tag">SystemUI</a><a class="mdui-ripple article_tags-link" href="/tags/framework/" rel="tag">framework</a>
      
    </footer>
    
  </article>
  
<script src="//cdn.bootcdn.net/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>

  <script>$("#main article .mdui-card-content img.fancybox").on("click",function(e){$.fancybox.open({src:$(this).attr("src")});});</script>


  <nav id="paginator">
    
      <a rel="prev" class="extend prev" href="/2024/02/13/2024-02-13/">
        <button aria-label="prev" class="mdui-btn mdui-btn-raised mdui-btn-icon mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_back</i></button>
        <span class="mdui-p-x-3" mdui-tooltip="{content: 'Android 14 双击power键唤起安全相机流程解析'}">上一篇</span>
      </a>
    
    <div class="spacer"></div>
    
      <a rel="next" class="extend next" href="/2024/02/11/2024-02-11/">
        <span class="mdui-p-x-3" mdui-tooltip="{content: 'Android 14 录屏流程解析'}">下一篇</span>
        <button aria-label="next" class="mdui-btn mdui-btn-raised mdui-btn-icon mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_forward</i></button>
      </a>
    
  </nav>





</main>
  <footer id="footer" class="mdui-m-t-5 mdui-p-y-3 mdui-color-theme">
  <div class="mdui-p-y-0 mdui-text-center">
    
    
    
    
    
    
    
      <a href="http://github.com/longzhiye" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe7ab;</i></a>
    
    
    
      <a href="https://www.zhihu.com/people/long-zhi-xie-61" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe6c0;</i></a>
    
    
    
      <a href="tencent://tencent:////message/?uin=951898105&Menu=yes" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe651;</i></a>
    
    
  </div>
  <div class="mdui-p-y-1 mdui-text-center">
    Copyright &copy; 2022 - 2025 龙之叶<br>
    Powered by <a href="https://hexo.io/" target="_blank" class="mdui-text-color-theme-accent">Hexo</a>
    <br>
      <span id="busuanzi_container_site_pv" style="display: none;"><i class="iconfont">&#xe7fd;</i> <span id="busuanzi_value_site_pv"></span></span> &nbsp;&nbsp;
      <span id="busuanzi_container_site_uv" style="display: none;"><i class="iconfont">&#xe601;</i> <span id="busuanzi_value_site_uv"></span></span>
    
  </div>
</footer>

  <button id="gotop" class="mdui-fab mdui-fab-fixed mdui-fab-hide mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_upward</i></button>
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
  
<script src="/js/mdui.js"></script>
<script src="/js/script.js"></script>

  
<script src="/custom.js"></script>

</body>
</html>
